class IUP_USER
-- Creates a user element in IUP, which is not associated to any interface 
-- element. It is used to map an external element to a IUP element. Its use is 
-- usually for additional elements, but you can use it to create an Ihandle* 
-- to store private attributes.
--
-- It is also a void container. Its children can be dynamically added using 
-- append or insert.

inherit
	IUP_WIDGET
		rename
			refresh as clear_attributes
		redefine
			clear_attributes
		end

create {ANY}
   user

feature {ANY}

	user
		local
			a_user: POINTER
		do
			a_user := int_user
			set_widget(a_user)
		end

	--- Operations

	clear_attributes
		-- (write-only, non inheritable): it will clear all attributes stored 
		-- internally and remove all references.
		do
			iup_open.set_attribute(Current, "CLEARATTRIBUTES", "Yes")
		end

	-- Commands to handle heirarchy
	
	append (new_child: IUP_WIDGET): detachable IUP_WIDGET
		-- Inserts an interface element at the end of the container, after 
		-- the last element of the container.
		-- Returns: the actual parent if the interface element was 
		-- successfully inserted. Otherwise returns Void.
		do
			Result := iup_open.iup_append(Current, new_child)
		end

   insert (ref_child: IUP_WIDGET; new_child: IUP_WIDGET): detachable IUP_WIDGET
		-- Inserts an interface element before another child of the 
		-- container.
		-- Returns: the actual parent if the interface element was 
		-- successfully inserted. Otherwise returns NULL
		do
			Result := iup_open.iup_insert(Current, ref_child, new_child)
		end

	get_child (pos: INTEGER): detachable IUP_WIDGET
		-- Returns the a child of the control given its position.
		-- Returns: the child or Void if there is none.
		do
			Result := iup_open.iup_get_child(Current, pos)
		end

	get_child_pos (child: IUP_WIDGET): INTEGER
		-- Returns the position of a child of the given control.
		-- Returns: the position of the desire child starting at 0, or -1 
		-- if child not found.
		do
			Result := iup_open.iup_get_child_pos(Current, child)
		end

	get_child_count: INTEGER
		-- Returns the number of children of the given control.
		do
			Result := iup_open.iup_get_child_count(Current)
		end

	get_next_child (child: IUP_WIDGET): detachable IUP_WIDGET
		-- Returns the a child of the given control given its brother.
		-- Returns: the child or Void.
		do
			Result := iup_open.iup_get_next_child(Current, child)
		end

	detach
		-- Detaches the interface element from its parent.
		do
			iup_open.iup_detach(Current)
		end
	
	get_parent: detachable IUP_WIDGET
		-- Return the parent of the element or void if does not have a parent.
		do
			Result := iup_open.iup_get_parent(Current)
		end

	get_brother: detachable IUP_WIDGET
		-- Return the next element in the parent where this element is 
		-- placed or void if there is none.
	
		do
			Result := iup_open.iup_get_brother(Current)
		end

feature {NONE}

	-- Internal
	
	int_user: POINTER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return IupUser();"
      end

end

-- The MIT License (MIT)

-- Copyright (c) 2016, 2019 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
